package com.example.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.user.entity.CrmBanner;
import com.example.user.mapper.CrmBannerMapper;
import com.example.user.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-10
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {


    @Autowired
    CrmBannerMapper crmBannerMapper;

    @Cacheable(value = "banner", key = "'bannerList'")
    @Override
    public List<CrmBanner> getBanner() {

        QueryWrapper<CrmBanner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 3");
        List<CrmBanner> bannerList = crmBannerMapper.selectList(queryWrapper);
        return bannerList;
    }
}
